package com.wsq.coroutine

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.wsq.coroutine.databinding.ActivityMainBinding
import com.wsq.coroutine.viewmodel.MainViewModel

/**
 * 搭一个协程 + databinding + viewModel + LiveData + Retrofit组建的demo
 *
 * 1.建立网络返回的数据结构类，采用LiveData结构
 * 2.构建好Retrofit网络请求类
 * 3.建立model类，负责数据处理
 * 4.建立ViewModel
 * 5.配置DataBinding布局文件
 */
class MainActivity : AppCompatActivity() {

    private val viewModel:MainViewModel by lazy {
        MainViewModel()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding:ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)

        binding.lifecycleOwner = this
        binding.viewModel = viewModel
        viewModel.getDemo()
    }
}